# -*- coding: utf-8 -*-
import numpy as np
feature = np.load("../data/skynet_feature_int32_HWC.npz")

#%% resize
big = np.zeros(shape=(360, 640, 3), dtype=np.int32)
big[..., :] = (0x66, 0xCC, 0xFF)

row_idx = np.arange(160) * 359 / 159
row_idx = (row_idx + 0.5).astype(np.uint32)

big[row_idx, 1:: 2] = feature["data0"]

row_mask = np.zeros(360, dtype=np.bool)
row_mask[row_idx] = True
assert np.sum(row_mask) == 160

# for i in range(360):
#     if i % 30 == 0:
#         print()
#     if row_mask[i]:
#         print("1,", end=' ')
#     else:
#         print("0,", end=' ')

#%% findmax
def find_max(output):
    assert output.shape == (20, 40, 10)
    res = np.empty(shape=(2, 7), dtype=np.int16)
    idx0 = np.unravel_index(output[..., 4].argmax(), (20, 40))
    idx1 = np.unravel_index(output[..., 9].argmax(), (20, 40))
    res[0, 0: 5] = output[idx0[0], idx0[1], 0: 5 ]
    res[0, 5: 7] = idx0[: : -1]
    res[1, 0: 5] = output[idx1[0], idx1[1], 5: 10]
    res[1, 5: 7] = idx1[: : -1]
    return res

fmax = find_max(feature["conv13"])

#%% dump
fish = dict(feature)
fish["big"] = big
fish["fmax"] = fmax.astype(np.int32).reshape(1, 2, 7)

np.savez("../data/feature_int32_HWC_big.npz", **fish)

